'use strict'

const Controller = require('egg').Controller
let OSS = require('ali-oss')
const { join } = require('path')

class UploadController extends Controller {
  async upload() {
    const { ctx } = this
    const file = ctx.request.files[0]
    let filename = join(`day13/`, ctx.genID(5) + '-' + file.filename)
    const result = await ctx.oss.put(filename, file.filepath)
    ctx.body = { url: result.url }
  }
}

module.exports = UploadController
